package com.web.base.user.service;

import com.blue.jdbc.JdbcDataSource;
import com.blue.jdbc.Page;
import com.web.base.user.dao.AddressDao;
import com.web.base.user.model.Address;
import com.web.core.util.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 收货地址业务层
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2018年06月26日
 */
@Service("userAddressService")
@Transactional
@JdbcDataSource(Const.DS_BASE)
public class AddressService
{
	@Autowired
	private AddressDao addressDao;
	
	public AddressService()
	{
	}
	
	public Address save(Address address)
	{
		if (address.getId() == null)
		{
			addressDao.save(address);
		}
		else
		{
			addressDao.update(address);
		}
		Address a = addressDao.get(address.getId());
		return a;
	}
	
	public Address get(Integer id)
	{
		Address address = addressDao.get(id);
		return address;
	}
	
	public Page<Address> list(Address address, Page<Address> page)
	{
		page = addressDao.list(address, page);
		return page;
	}
	
	public List<Address> list(Address address)
	{
		List<Address> list = addressDao.list(address);
		return list;
	}
	
	public void delete(Address address)
	{
		addressDao.delete(address);
	}
	
}
